/*
 * @Author: Choisaaaa
 * @Date: 2018/5/22  21:42
 */

require("./seller-order-detail.css");
var nav = require("page/common/nav/nav.js");
require("page/common/header/header.js");
var _mm = require("util/mm.js");
var navSide = require("page/common/nav-side/nav-side.js");              //侧边导航模块
var _order = require("service/seller/seller-order-service.js");
var templateIndex = require("./seller-order-detail.string");

var page = {
    data : {
        orderNo : _mm.getUrlParam("orderNo") || ""
    },

    init : function(){
        this.onLoad();
        this.bindEvent();
    },
    onLoad : function () {
        this.onLoadSide();            //加载侧边导航
        this.loadOrderDetail();       //加载卖家的订单详情
    },
    bindEvent : function () {
        this.clickSendBtn();
    },
    clickSendBtn : function () {
        var _this = this;
        $(document).on("click",".order-send", function () {
            _order.getSellerSendGoods(_this.data.orderNo,
                function (res) {
                    _mm.successTips(res.data);
                    _this.loadOrderDetail();
                }, function (err) {
                    _mm.errorTips(err.msg);
                });

        });
    },
    loadOrderDetail : function () {
        var _this = this,
            orderDetailHTML = "",
            $content = $(".content");
        _order.getSellerOrderDetail({
            orderNo : _this.data.orderNo
        }, function (res) {
            _this.dataFilter(res.data);
            orderDetailHTML = _mm.renderHtml(templateIndex,res.data);
            $content.html(orderDetailHTML);
        }, function () {

        });
    }
    ,
    /** 1.初始化加载页面时的数据渲染 **/
    onLoadSide : function(){ //1.1:初始化侧边导航
        navSide.init({
            name : "seller-center"
        });
    },

    //3.辅助函数
    dataFilter : function (data) { // 数据的适配
        data.needSend        = data.status == 20; //未支付
        data.isSended   = data.status == 40;
    }

}
$(function () {
    page.init();
});